package com.qwz.example.itreator.impl;

import com.qwz.example.itreator.Aggregate;
import com.qwz.example.itreator.Iterator;
import com.qwz.example.model.PayModel;

/**
 * @author Qiuwuzhi
 * @version V1.0
 * @Description: 被客户方收购的那个公司的工资管理类
 * @Package com.qwz.example.SalaryManager
 * @date 2019/12/26 15:21
 */
public class SalaryManager extends Aggregate {
    private PayModel[] payModels;

    public PayModel[] getPayModels() {
        return payModels;
    }

    public void calcSalary() {
        PayModel model1 = new PayModel();
        model1.setPay(3300);
        model1.setUserName("wq");

        PayModel model2 = new PayModel();
        model2.setPay(2300);
        model2.setUserName("lw");

        payModels = new PayModel[2];
        payModels[0] = model1;
        payModels[1] = model2;
    }

    @Override
    public Iterator createIterator() {
        return new ArrayIteratorImpl(this);
    }
    /**
     * 获取索引对应的元素
     * @param index
     * @return
     */
    public Object get(int index){
        Object retObj = null;
        if (index<payModels.length){
            retObj = payModels[index];
        }
        return retObj;
    }

    /**
     * 获取聚合对象的大小
     * @return
     */
    public int size(){
        return this.payModels.length;
    }
    
}
